﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.DBM;
using System.Web.UI.HtmlControls; 

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class DC_InvestFactPopup : System.Web.UI.UserControl
    {


    
        private string id;
        private object _dataItem = null;

        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }

        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
            IncludeJava();

     
          
            lblInvSeq.Text = Session["inv_seq"].ToString() ;  
            
       
            if (!IsUserControlPostBack)
            {
                bindCombo();
                this.ViewState.Add("IsUserControlPostBack", true);
            }
            if (DataItem != null)
            {
 
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    bindCombo();
                    this.ViewState.Add("IsUserControlPostBack", true);
                }
               
                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }
        }


        public void IncludeJava()
        {
            HtmlGenericControl script = new HtmlGenericControl();
            script.TagName = "script";
            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("src", "../../Scripts/jsfunction.js");
            Page.Header.Controls.Add(script);
        }

        protected void Page_Load(object sender, EventArgs e)
        {

              
              

        
        }
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

        
        //**************  Insert  ************************************
        protected void btnAddnew_Click(object sender, EventArgs e)
        {

            int inv_seq,inv_emp_seq;


            inv_emp_seq = int.Parse(lblEmpSeq.Text);
            inv_seq = int.Parse(lblInvSeq.Text);

            InvestFactBLL obj = new InvestFactBLL();

            obj.InsertDtls(inv_seq, inv_emp_seq, "1");   


        }


        protected void btnUpdate_Click(object sender, EventArgs e)
        {
   




        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        private IEmployeeBLL empBLL = new EmployeeBLL();
        protected void btnFindEmp_Click(object sender, ImageClickEventArgs e)
        {


            string st = Hide.Value;
            //if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
            //    st = DataBinder.Eval(DataItem, "req_seq").ToString();
            EmployeeInfo infoEmp;
            IList<EmployeeInfo> infoList = empBLL.ListEmployees(st);
            infoEmp = infoList[0];


           // infoEmp.Class.Sequence != null

            lblEmpSeq.Text = infoEmp.Sequence.ToString();
            lblPosName.Text = infoEmp.Position.Name != null ? infoEmp.Position.Name.ToString() : "";
            lblClassName.Text = ""; // infoEmp.Position.ClassSpecification.Name != null ? infoEmp.Position.ClassSpecification.Name.ToString() : "";
            lblJobsiteName.Text = infoEmp.WorkingJobSite.Name != null ? infoEmp.WorkingJobSite.Name.ToString() : "";
            lblPosRefNo.Text = infoEmp.Position.RefNo != null ? infoEmp.Position.RefNo.ToString(): "";
            txtEmp.Text = infoEmp.Person.FirstName.ToString() + "   " + infoEmp.Person.LastName.ToString();


          
               
        }


        private void bindCombo()
        {
            InvestFactBLL obj = new InvestFactBLL();

            DataTable dt;
            dt = obj.SelectEmpType(); 

   ComboEmpType.DataValueField = "emp_type_seq";
   ComboEmpType.DataTextField = "emp_type_name";
   ComboEmpType.DataSource = dt;
   ComboEmpType.DataBind(); 

        }





        protected void btnFindEmp_Load(object sender, EventArgs e)
        {
            if (DataItem is Telerik.Web.UI.GridInsertionObject)
            {

                Session["ETID"] = ComboEmpType.SelectedValue;  
              
                string ETID = Session["ETID"].ToString();
              
             //   btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogEmp.aspx?ETID=" + ETID + "&JSID=1','../frmIframe.html',700,500)");
             btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogInvestFact.aspx?ETID=" + ETID + "','../frmIframe.html',700,500)");
            }
        }

        protected void ComboEmpType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {

            Session["ETID"] = ComboEmpType.SelectedValue;

            string ETID = Session["ETID"].ToString();

            //   btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogEmp.aspx?ETID=" + ETID + "&JSID=1','../frmIframe.html',700,500)");
            btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogInvestFact.aspx?ETID=" + ETID + "','../frmIframe.html',700,500)");

        }
    }
}